#include <stdio.h>
#include <string.h>

int romanToInt(char* s)
{
    int a = 0;
    int len = strlen(s);
    for(int i = 0;i < len;i++)
    {
        switch(s[i])
        {
            case 'I':
                if(s[i+1] == 'V' || s[i+1] == 'X')
                    a -= 1;
                else
                    a += 1;
                break;
            case 'V':
                a += 5;
                break;
            case 'X':
                if(s[i+1] == 'L' || s[i+1] == 'C')
                    a -= 10;
                else
                    a += 10; 
                break;
            case 'L':
                a += 50;
                break;
            case 'C':
                if(s[i+1] == 'D' || s[i+1] == 'M')
                    a -= 100;
                else
                    a += 100;
                break;
            case 'D':
                a += 500;
                break;
            case 'M':
                a += 1000;
                break;
        }
    }
    return a;
}

int main()
{
    char s[] = "MCMXCIV";
    int n = romanToInt(s);
    printf("%d\n",n);
    return 0;
}